namespace KinonekoSoftware.CodariaDB.Documents.Theories.Chikara
{
    public sealed class TheoryEngine_Chikara : TheoryEngine<Chikara>
    {

        public void Add(Chikara element)
        {
            if (element is null)
            {
                return;
            }

            //
            //
            ((IGlossaryOperation)element).Add(this);

            //
            //
            InsideDB.Insert(element);
            InternalCollection.Add(element);
            Modified();
        }

        public void Update(Chikara element)
        {
            if (element is null)
            {
                return;
            }

            //
            //
            ((IGlossaryOperation)element).Update(this);

            //
            //
            InsideDB.Update(element);
            Modified();
        }
        
        
        public void Clear()
        {
            //
            //
            foreach (var element in InternalCollection)
            {
                //
                //
                ((IGlossaryOperation)element).Remove(this);
                
                //
                //
                InsideDB.Delete(element.Id);
                
                //
                //
                InternalCollection.Remove(element);
            }
            
            
            Modified();
        }

        public void Remove(Chikara element)
        {
            if (element is null)
            {
                return;
            }

            //
            //
            ((IGlossaryOperation)element).Remove(this);

            //
            //
            InsideDB.Delete(element.Id);
            InternalCollection.Remove(element);
            Modified();
        }


        protected override void OnInitialize()
        {
            Add(new Chikara { Id = ID.Get(), Name = "战力排行 #1", Minimum = 100, Maximum = 1000,  });
            Add(new Chikara { Id = ID.Get(), Name = "战力排行 #2", Minimum = 1000, Maximum = 10000,  });
            Add(new Chikara { Id = ID.Get(), Name = "战力排行 #3", Minimum = 10000, Maximum = 100000,  });
            Add(new Chikara { Id = ID.Get(), Name = "战力排行 #4", Minimum = 100000, Maximum = 1000000,  });
        }
        
        public override string EngineID            => EngineNames.Theory_Chikara;
        public override string GetCollectionName() => CollectionNames.Theory_ChikaraDB;
    }
}